cmake_minimum_required(VERSION 3.14)
project(websocket_test)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
#set(CMAKE_AUTOUIC ON)
#set(CMAKE_AUTOMOC ON)
#set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 11)

if(WIN32)
    add_definitions(
        -DWIN32
        -D_WIN32_WINNT=0x0A00
        -DYAML_CPP_STATIC_DEFINE
        -D_CRT_SECURE_NO_WARNINGS
        -DUWS_NO_ZLIB
        #-DLIBUS_NO_SSL
        -DLIBUS_USE_OPENSSL
        -DLIBUS_USE_LIBUV
    )
else()
    set(CMAKE_POSITION_INDEPENDENT_CODE ON)
        add_definitions(
        -DYAML_CPP_STATIC_DEFINE
        -DUWS_NO_ZLIB
        #-DLIBUS_NO_SSL
        -DLIBUS_USE_OPENSSL
        -DLIBUS_USE_LIBUV
    )
endif()

#设置win32运行时库
if(WIN32)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_MSVC_RUNTIME_LIBRARY_LINKAGE_Debug "MultiThreadedDebug$<$<CONFIG:Debug>:_DLL>")
else()
set(CMAKE_MSVC_RUNTIME_LIBRARY_LINKAGE_Release "MultiThreaded$<$<CONFIG:Release>:_DLL>")
endif()
endif()

include_directories(../libuvc/include/)
include_directories(./src)
include_directories(../OpenSSL/include/)
include_directories(./uSockets/src/)
include_directories(./src)

#if(WIN32)
include_directories(./libuv/include/)
add_subdirectory(./libuv)
#endif()

add_subdirectory(./uSockets)

add_executable(
    websocket_server_test
    ./tests/WSServerTest.cpp
)

if(WIN32)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    #target_link_directories(websocket_server_test PRIVATE ../libuv/lib/Debug/)
    target_link_directories(websocket_server_test PRIVATE ../OpenSSL/lib/Debug/)
else()
    #target_link_directories(websocket_server_test PRIVATE ../libuv/lib/Release/)
    target_link_directories(websocket_server_test PRIVATE ../OpenSSL/lib/Release/)
endif()
endif()

target_link_libraries(websocket_server_test usockets)

#win32系统库函数
if(WIN32)
target_link_libraries(websocket_server_test libssl)
target_link_libraries(websocket_server_test libcrypto)
target_link_libraries(websocket_server_test Iphlpapi)
target_link_libraries(websocket_server_test Dbghelp)
target_link_libraries(websocket_server_test Userenv)
target_link_libraries(websocket_server_test Crypt32)
target_link_libraries(websocket_server_test uv_a)
target_link_libraries(usockets libssl)
target_link_libraries(usockets libcrypto)
target_link_libraries(usockets uv_a)
else()
#target_link_directories(usockets PRIVATE ./build/libuv/)
target_link_libraries(usockets libssl.a)
target_link_libraries(usockets libcrypto.a)
#target_link_libraries(usockets libuv.a)
target_link_libraries(usockets uv_a)
#target_link_libraries(websocket_server_test PRIVATE ./build/libuv/)
target_link_libraries(websocket_server_test libssl.a)
target_link_libraries(websocket_server_test libcrypto.a)
#target_link_libraries(websocket_server_test libuv.a)
target_link_libraries(websocket_server_test uv_a)
endif()
